﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace Krist_em_up.Components
{
    public class Clavier : GameComponent
    {
        KeyboardState kb_state, prev_state;

        public KeyboardState PreviousState
        {
            get { return prev_state; }
            protected set  { prev_state = value; }
        }
        public Clavier(Game agame)
            : base(agame)
        {

        }
        public override void Update(GameTime gameTime)
        {
            prev_state = kb_state;
            kb_state = Keyboard.GetState();
            base.Update(gameTime);
        }
        
        public void Previous()
        {
            kb_state = prev_state;
        }

        public bool IsKeyDown(Keys k)
        {
            return kb_state.IsKeyDown(k);
        }

        public bool HasBeenPressed(Keys k)
        {
            return (prev_state.IsKeyDown(k) && kb_state.IsKeyUp(k));            
        }
        public Keys? GetPressedKey()
        {
            Keys[] k = kb_state.GetPressedKeys();
            if (k.Length != 0)
                return k[0];
            else
                return null;
        }
    }
}
